import request from "./request";


// 登录
export function LoginApi(data){
    return request({
        url:'/login',
        method:'POST',
        data,
    })
}

// 左侧
export function getmenusApi(){
    return request({
        url:'/menus',
        method:'GET',
    })
}

// 用户列表的渲染
export function getUsersApi(params){
    return request({
        url:'/users',
        method:'GET',
        params,
    })
}

// 添加用户
export function addUsersApi(data){
    return request({
        url:'/users',
        method:'POST',
        data,
    })
}

// 删除用户
export function delUsersApi(id){
    return request({
        url:`/users/${id}`,
        method:'delete',
    })
}

// 修改用户状态
export function changeUsersApi(id,type){
    return request({
        url:`/users/${id}/state/${type}`,
        method:'PUT',
    })
}

//用户编辑的数据回填 
export function eEditUsersApi(id){
    return request({
        url:`/users/${id}`,
        method:'GET',
    })
}

// 提交编辑用户数据
export function eEditupUsersApi(id,data){
    return request({
        url:`/users/${id}`,
        method:'PUT',
        data
    })
}

// 用户角色数据列表
export function RoleListUsersApi(){
    return request({
        url:`/roles`,
        method:'GET',
    })
}

// 分配用户角色
export function RoleupUsersApi(id,rid){
    return request({
        url:`/users/${id}/role`,
        method:'PUT',
        data:{rid}
    })
}


// 权限列表
export function rightApi(type = 'list'){
    return request({
        url:`/rights/${type}`,
        method:'GET',
    })
}

// 角色列表
export function rolesApi(){
    return request({
        url:`/roles`,
        method:'GET',
    })
}

// 添加角色
export function AddRolesApi(data){
    return request({
        url:`/roles`,
        method:'post',
        data
    })
}

// 角色列表权限删除
export function delrightsApi(roleId,rightId){
    return request({
        url:`/roles/${roleId}/rights/${rightId}`,
        method:'delete',
    })
}

// 角色列表删除
export function delRolesApi(id){
    return request({
        url:`/roles/${id}`,
        method:'delete',
    })
}

// 角色编辑
export function editRolesApi(id){
    return request({
        url:`/roles/${id}`,
        method:'get',
    })
}

// 修改角色提交
export function updataRolesApi(id,data){
    return request({
        url:`/roles/${id}`,
        method:'put',
        data
    })
}

// 角色授权接口
export function changeRolesApi(roleId,rids) {
    return request({
      url: `roles/${roleId}/rights`,
      method: 'post',
      data:{rids}
    })
}

// 商品列表数据
export function goodsApi(params) {
    return request({
      url: `/goods`,
      method: 'get',
      params
    })
}

// 商品删除
export function delGoodsApi(id) {
    return request({
      url: `/goods/${id}`,
      method: 'delete',
    })
}

// 商品编辑
export function editGoodsApi(id) {
    return request({
      url: `/goods/${id}`,
      method: 'get',
    })
}

// 商品编辑提交
export function updateGoodsApi(id,data) {
    return request({
      url: `/goods/${id}`,
      method: 'put',
      data
    })
}


// 封装商品分类接口
export function getGoodsCateList(params) {
    return request({
      url: '/categories',
      method: 'GET',
      params
    })
  }
  
  // 获取商品参数接口
  export function getGoodsParams(cateId, sel = 'many') {
    return request({
      url: `categories/${cateId}/attributes`,
      method: 'GET',
      params: { sel }
    })
  }
  
  // 添加商品接口
  export function addGoods(data) {
    return request({
      url: '/goods',
      method: 'POST',
      data
    })
  }